package view;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import model.*;

/* Cette classe s'occupe de l'affichage de la fen�tre de confirmation de commande */
public class VueConfirmation extends JFrame implements Observer{
		
	public VueConfirmation(){
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Confirmation");
		setSize(400, 250);
		setResizable(false);
		
		Container cont = getContentPane();
		mainPanel = new JPanel();
		mainPanel.setLayout(new GridLayout(2,1,0,0));
		btnPanel = new JPanel();
		btnPanel.setLayout(new FlowLayout());
		
		txtConfirmation = new JTextArea();
		txtConfirmation.setEnabled(false);
		btnOk = new JButton("OK");		
		btnPanel.add(btnOk);
		mainPanel.add(txtConfirmation);
		mainPanel.add(btnPanel);
		cont.add(mainPanel);
	}
	
	public void AfficherNum(Commande comm){
		
		String confirmationInfo = "Confirmation\n___________________________________________________\n\n";
		confirmationInfo += ("Date et temps local:     " + comm.getDateTimeAdded() + "\n\n");
		confirmationInfo += ("Votre numero de confirmation est:" + comm.getNumber());
		txtConfirmation.setText(confirmationInfo);
	}
	
	
	public void update(Observable obs, Object o) {
		if(o instanceof Commande){
			AfficherNum((Commande)o);
			setVisible(true);
		}
		
	}

	public void addConfirmationOkListener(ActionListener listener){
		btnOk.addActionListener(listener);
	}
	
	private static final long serialVersionUID = 1L;
	private JTextArea txtConfirmation;
	private JPanel mainPanel;
	private JPanel btnPanel;
	private JButton btnOk;



	
}
